import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-03-12
 * Time: 9:07
 */
public class Exercise {


    //输出闰年
    public static void main12(String[] args) {
        int i=1000;
        for ( i = 1000; i <=2000 ; i++) {
            if( (i%4==0 && i%100!=0 )||i%400==0) {
                System.out.println(i);
            }
        }
    }
    //打印素数
    public static void main10(String[] args) {
        int i=2,j=0;
        for (i = 2; i <=100 ; i++) {
            for ( j = 2; j <=Math.sqrt( i ) ; j++) {
                if( i%j == 0){
                    break;
                }
            }
            if(j>=i){
                System.out.println(i);
            }
        }
    }
    //判断素数
    public static void main9(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个数 >: ");
        int n = scan.nextInt();
        int i=0;
        for ( i = 2; i < n; i++) {
            if(n % i == 0) {
                break;
            }
        }
        if( i>=n && n>=2 ){
            System.out.println(n+"是素数");
        } else {
            System.out.println(n +"不是素数");
        }
        scan.close();
    }

    //根据输入的年龄, 来打印出当前年龄的人是少年(低于18), 青年(19-28), 中年(29-55), 老年(56以上)
    public static void main8(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入年龄 >: ");
        int age = scan.nextInt();
        if(age >= 0 && age <= 18 ) {
            System.out.println("少年");
        } else if(age >= 19 && age <= 28 ){
            System.out.println("青年");
        } else if(age >= 29 && age <= 55 ){
            System.out.println("中年");
        } else if(age >= 56 ){
            System.out.println("老年");
        }
        scan.close();
    }
    /*求出0～999之间的所有“水仙花数”并输出。(“水仙花数”是指一个三位数，
    其各位数字的立方和确好等于该数本 身，如；153＝1＋5＋3?，则153是一个“水仙花数“。）
     */
    public static int myPow (int n,int count) {
        int s = 1;
        while( count!=0 )
        {
            s = s*n;
            count--;
        }
        return s;
    }
    public static void main33(String[] args) {
        int i=0;
        for(;i<999_999;i++){
            int num = i;
            int count = 0;
            while(num != 0) {
                count++;
                num/=10;
            }
            int sum = 0;
            int x = i;
            while( x!=0){
                int t = x%10;
                sum = sum + myPow(t,count);
                x/=10;
            }
            if(sum == i){
                System.out.println(i);
            }
        }
    }
    //求两个正整数的最大公约数
    public static void main6(String[] args) {
        Scanner scan =new Scanner(System.in);
        System.out.println("请输入两个正整数");
        int m = scan.nextInt();
        int n= scan.nextInt();
        //辗转相除法
        int c =0 ;
        while((( c = m%n ) != 0)){
            m=n;
            n=c;
        }
        System.out.println("最大公约数为>: "+n);
    }
    //获取一个数二进制序列中所有的偶数位和奇数位， 分别输出二进制序列
    public static void main(String[] args) {
        Scanner scan =new Scanner(System.in);
        System.out.println("请输入要转换的数字");
        int x = scan.nextInt();
        int odd_number = x&(0x5555_5555);
        int even_number = x&(0xaaaa_aaaa);
        System.out.println("奇数的二进制序列 >: ");
        for (int i = 31; i >=0; i--) {
            System.out.print( ((odd_number >>> i) & 1)+" " );
        }
        System.out.println();
        System.out.println("偶数的二进制序列 >: ");
        for  (int i = 31; i >=0; i--) {
            System.out.print( ((even_number >>> i) & 1)+" ");
        }
        scan.close();
    }
    //计算一个数，二进制1的个数
    public static void main4(String[] args) {
        Scanner scan = new Scanner(System.in);
        int count = 0;
        int n = scan.nextInt();
        while( n!=0) {
            count++;
            n = n & (n-1);
        }
        System.out.println(count);
    }
    //模拟登录
    public static void main3(String[] args) {
        Scanner scan = new Scanner(System.in);
        String true_name = "1145285312";   //正确的用户名
        String true_password = "83420134"; //正确的密码
        int n = 3;
        int i = 1,count = 3;
        while(i<=n){
            System.out.println("请输入用户名 >: ");
            String user_name = scan.nextLine();
            System.out.println("请输入密码 >: ");
            String user_password = scan.nextLine();
             if( ( user_name.equals(true_name) ) && ( user_password.equals(true_password) ) ){
                 System.out.println("登陆成功！");
                 break;
             } else {
                 count--;
                 System.out.println("用户名或密码错误，请重新输入");
                 System.out.println("你还有"+count+"次机会");
             }
             i++;
        }
        scan.close();
    }
    //输出 n*n 乘法口诀表
    public static void main13(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n= scan.nextInt();
        int i=0,j=0;
        for ( i=1 ; i<=n ; i++){
            for (j = 1 ; j<=i ; j++){
                System.out.printf("%d * %d = %d\t",j,i,i*j);
            }
            System.out.println();
        }
        scan.close();
    }
    //使用 Scanner 循环读取 N 个数字，并求取其平均值
    public static void main1(String[] args) {
        Scanner scan = new Scanner(System.in);
        double sum=0,aver=0;
        int i=0;
        while( scan.hasNextInt() ) {
            int num = scan.nextInt();
            sum= sum + num;
            i++;
    }
        aver = sum / i ;
        System.out.println("n个数之和 = "+ sum );
        System.out.println( "平均数 = " + aver );
        scan.close();
    }
}
